function recursion(list, pid) {
  const data = []
  list.forEach(element => {
    if (pid === element.pid) {
      const children = recursion(list, element.id)
      if (children.length > 0) {
        element.children = children
      }
      data.push(element)
    }
  })
  // list.forEach(item => {
  //   if (item.id !== pid) {
  //     const parent = list.find(value => value.id === item.pid)
  //     if (parent) {
  //       parent.children.push(item)
  //       data.push(parent)
  //     }
  //     data = data.filter(value => value.id !== parent.id)
  //   }
  // })
  return data
}
export default recursion
